<include file="Public:header" />
<include file="Public:leftside" />
<link rel="stylesheet" type="text/css" href="/Store/css/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="/Store/css/cuoxiao.css"/>
<script src="/static/js/layer2.1/layer.js"></script>
<style>
    .hide_m{display: none}
    .modal-infp-style{width:90%;margin:10px auto;}
    .modal-infp-style table{width:100%;}
    .modal-infp-style table tr td{border: 1px solid #e6e6e6; padding: 10px;}
    .modal {width: 800px;height: 420px;}
    .modal-dialog{padding: 0;}
</style>
<div class="main-content">
    <div class="breadcrumbs breadcrumbs-fixed" id="breadcrumbs">
        <ul class="breadcrumb" style="margin: 0;">
            <li> <i class="icon-home home-icon"></i> <a href="/">首页</a> </li>
            <li class="active">众筹管理</li>
        </ul>

    </div>
    <div class="page-content" style="padding: 0px;">

        <div class="search_box">
            <div class="col-sm-8" style="padding: 8px 0px;">
                <a href="/Crowdfunding/add/" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i> 添加众筹</a>
            </div>
        </div>

        <div class="listContent" style="margin: 10px 0 0 0;">
            <table class="table table-striped table-bordered table-hover" width="100%" border="0" cellpadding="0" cellspacing="0" >
                <thead>
                <tr class="f_black bg_gray">
                    <th style="width: 50px;" align="center">ID</th>
                    <th style="width: 15%;">项目名称</th>
                    <th>产品名称</th>
                    <th>启动资金</th>
                    <th>限购人数</th>
                    <th>结束时间</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>

                <foreach name="crowdfundinglist" item="cf">
                    <tr class="list" >

                        <td>{$cf.id}</td>
                        <td style="text-align:left;">{$cf.project_name}</td>
                        <td>{$cf.product_name}</td>
                        <td>{$cf.total_money}</td>
                        <td>{$cf.total_num}</td>
                        <td>{$cf.end_time}</td>
                        <td>
                        <php>
                            $now_time=date('Y-m-d H:i:s',time());
                            if($cf["start_time"]>$now_time):
                        </php>
                            未开始
                            <php>
                                elseif($cf["start_time"]<=$now_time&&$cf["end_time"]>=$now_time):
                            </php>
                                众筹中
                            <php>
                                elseif($cf["end_time"]<$now_time):
                            </php>
                                已结束
                            <php>endif;</php>

                        </td>
                        <td><a href="{:U('edit',array('id'=>$cf['id']))}">编辑</a>
                            &nbsp;<a href="javascript:void(0);" onclick="crowdfundingInfo({$cf.id})">详情</a>
                            <a href="{:U('delete',array('id'=>$cf['id']))}" data-id="{$cf['id']}"  class="js-ajax-delete" >删除</a>
                        </td>

                    </tr>
                </foreach>
                </tbody>
            </table>
            <div class="paging">{$page}</div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $('.js-ajax-delete').on('click', function (e) {
        e.preventDefault();
        var $_this = this,
            $this = $($_this),
            href = $this.prop('href'),
            data = $this.data('id');
        layer.confirm('确定要删除吗？', {
            btn: ['确定','取消'] //按钮
        }, function(){
            $.ajax({
                url:href,
                type:"POST",
                dataType:'json',
                data:data,
                success:function (json) {
                    console.log(json.data.post);
                    var status = 1;
                    if(!json.status || json.status != 1) status = 3;
                    if(status == 1){
                        layer.closeAll();
                    }
                    layer.alert(json.message,function(){
                        if(status != 1){
                            layer.closeAll();
                        }
                        if(json.data.result && json.data.result.redirect_url){
                            window.location.href = json.data.result.redirect_url;
                        }else if(json.data.url ){
                            window.location.href = json.data.url;
                        }
                    });
                }
            });
        });

    });
    function crowdfundingInfo(id){
        $("#crowdfundingInfo").modal("show");
        $.ajax({
            type:"post",
            url : "{:U('Crowdfunding/getCrowdfundingInfo')}",
            data : {
                "id" : id
            },
            success : function(data) {
                $("#project_name").text(data["project_name"]);
                $("#product_name").text(data["product_name"]);
                $("#total_money").text(data["total_money"]+"元");
                $("#now_money").text(data["now_money"]+"元");
                $("#total_num").text(data["total_num"]);
                $("#num").text(data["num"]);
                $("#days").text(data["days"]+"天");
                $("#time").text(data["start_time"]+"到"+data["end_time"]);
            }
        })
    }

</script>

<!-- 模态框（Modal） -->
<div class="modal fade hide_m" style="height: 600px;" id="crowdfundingInfo" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">众筹详情</h4>
            </div>
            <div class="modal-body">
                <div class="modal-infp-style">
                    <table>
                        <tr>
                            <td>项目名称</td>
                            <td id="project_name"></td>
                        </tr>
                        <tr>
                            <td>产品名称</td>
                            <td id="product_name"></td>
                        </tr>
                        <tr>
                            <td>启动资金</td>
                            <td id="total_money"></td>
                        </tr>
                        <tr>
                            <td>已筹到</td>
                            <td id="now_money"></td>
                        </tr>
                        <tr>
                            <td>限额人数</td>
                            <td id="total_num"></td>
                        </tr>
                        <tr>
                            <td>已支持人数</td>
                            <td id="num"></td>
                        </tr>
                        <tr>
                            <td>众筹成功后多久可以发货</td>
                            <td id="days"></td>
                        </tr>
                        <tr>
                            <td>有效时间</td>
                            <td id="time"></td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">关闭</button></div>
        </div>
    </div>
</div>
<include file="Public:footer" />